package com.jhx.video.draftbox

import android.os.Bundle
import com.jhx.common.framework.QuickBaseActivity
import com.jhx.common.model.Event
import com.jhx.common.model.Video
import com.jhx.video.R
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe

/**
 * 草稿箱
 *
 * @author Jack 2018-03-07 17:29
 */
class DraftBoxActivity : QuickBaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_home)
        val bundle = Bundle()
        push(DraftBoxFragment::class.java, bundle)
        if(!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this)
        }
    }

    override fun containerId(): Int {
        return R.id.view_container
    }

    override fun showToolbar(): Boolean {
        return false
    }

    override fun onDestroy() {
        super.onDestroy()
        if(EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this)
        }
    }

    @Subscribe
    fun onEvent(event: Event?) {
        if(event != null && event.code == Video.CODE_POST_SUCCESS) {
            finish()
        }
    }
}